#include "kgmtoolbutton.h"

KGMToolButton::KGMToolButton(QWidget *parent, QIcon icon, char* type) : QToolButton(parent) {
	
	setIcon(icon);
	pixmap = icon.pixmap(50,50);
	strType = type;
}

void KGMToolButton::mousePressEvent(QMouseEvent *event){
	if (event->button() == Qt::LeftButton){
		dragStartPosition = event->pos();
	}
}

void KGMToolButton::mouseMoveEvent(QMouseEvent *event) {
	if (!(event->buttons() & Qt::LeftButton)){
		return;
	}
	if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance()){
		return;
	}
	
	QString strTmp = "image/";
	QByteArray itemData;
	QDataStream dataStream(&itemData, QIODevice::WriteOnly);

	dataStream << pixmap;

	QMimeData *mimeData = new QMimeData;
	mimeData->setData(strTmp.append(strType), itemData);
	
	QDrag *drag = new QDrag(this);
	drag->setMimeData(mimeData);
	drag->setPixmap(pixmap);

	Qt::DropAction dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
}
